package com.neu.db;

import android.content.Context;

import java.util.List;

import androidx.room.Room;

public class CarMode implements ICarMode {
    private static volatile CarMode carMode;
    private CarDataBase carDataBase;
    private CarDao carDao;

    private CarMode(Context context){
        carDataBase= Room.databaseBuilder(context,CarDataBase.class,"Car.db")
            .allowMainThreadQueries()
            .build();
        carDao=carDataBase.carDao();
    }

    public static CarMode getInstance(Context context){
        if(carMode==null){
            synchronized (CarMode.class){
                if(carMode==null){
                    carMode=new CarMode(context);
                }
            }
        }
        return carMode;
    }
    @Override
    public void add(Car car) {
        carDao.insertCar(car);
    }

    @Override
    public List<Car> findAll() {
        return carDao.getAll();
    }
}
